package com.yuju.account.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.yuju.account.dao.IUnitAccountBookDao;
import com.yuju.account.dao.entity.UnitAccountBook;
import com.yuju.account.dao.mapper.UnitAccountBookMapper;
import com.yuju.account.model.UnitAccountBookModel;
import com.yuju.common.PageModel;
import com.yuju.common.core.dao.AbstractBaseDao;
import com.yuju.persist.base.mapper.BaseMapper;
/**
 * 类名：UnitAccountBookDaoImpl  <br />
 *
 * 功能：
 *
 * @author : jiaokn <br />
 * @Date : 2017年11月27日 上午10:35:57  <br />
 * @version : 1.1 <br />
 */
@Repository
public class UnitAccountBookDaoImpl extends AbstractBaseDao<UnitAccountBookModel, UnitAccountBook, String> implements IUnitAccountBookDao {
	
	@Autowired 
	private UnitAccountBookMapper unitAccountBookMapper;
	
	@Override
	public BaseMapper<UnitAccountBook, String> getMapper() {
		// TODO Auto-generated method stub
		return unitAccountBookMapper;
	}

	@Override
	public PageModel listAndSum(UnitAccountBookModel unitAccountBookModel, Integer currentPage, Integer rows) {
		PageModel pageModel = new PageModel(currentPage, rows);
		Map<Object, Object> beanMap = getBeanMap(unitAccountBookModel, currentPage, rows);
		
		//获得总数
		Integer total = countByMap(beanMap);
		if (total == null || total == 0) {
			pageModel.setTotal(total);
			return pageModel;
		}
		
		// 设置总记录数到返回结果中
		pageModel.setTotal(total);
		List<UnitAccountBook> list = unitAccountBookMapper.listAndSum(beanMap);
		// 转换为Model泛型的List
		List<UnitAccountBookModel> modelList = convertP2M(list);
		
		pageModel.setRows(modelList);
		return pageModel;
	}

	@Override
	public Integer countByMap(Map<Object, Object> beanMap) {
		return unitAccountBookMapper.countByMap(beanMap);
	}

	@Override
	public int updateSettle(Map<String, Object> map) {
		return unitAccountBookMapper.updateSettle(map);
	}

}
